/*
 *  key_handler.h
 *  pire2pireV1
 *
 *  Created by jihed kamkoum on 04/05/10.
 *  Copyright 2010 ENSEIRB. All rights reserved.
 *
 */
#ifndef KEY_HANDLER_H_
#define KEY_HANDLER_H_

#include "../serveur/serveur.h"
#define gras(bool) printf("%c[%dm",27,bool)
#define couleur(param) printf("\033[%dm",param)
typedef struct _sended{
	int semid;
	ListeDownload * listeDownload;
	pthread_mutex_t * downloadTableAccess;
	int socket;
	char * path;
}sended;
typedef struct _tchecksum{
	int sock;
	int semid;
	int nbblock;
	const char * cmd;

}tchecksum;



typedef struct _tget{
	download * down;
	int semid;
	ListeDownload * listeDownload;
	pthread_mutex_t * downloadTableAccess;
	char * path;
	int delay;
	int begin;
	int end;
}tget;

/**
 *
 *cette fonction renvoi la socket ouverte par effet de bord.
 */
int connect_program(const char * ip,int port,const char * ip_s,int port_s,int * sock ,pthread_mutex_t * socketAccess);
/*
 *Gestion de la commande get cle debut fin
 *
 */
void get(int * sock,int semid,char *path,const char * message,ListeDownload * listeDownload,pthread_mutex_t * downloadTableAccess);
/*
 *
 *Getion de la commande neighbourhood
 */
void neighbourhood(int * sock,const char * message,int semid);
/*
 *
 *thread de gestion du retour serveur sur la commande neighbourhood
 */
void * f_thread_neighbourhood(int * args);

void * f_thread_get(tget * args);
void list(int * sock,const char * message,int semid,filelist_t * listeFichiers,pthread_mutex_t *fileTableAccess);
void traffic(int * sock,const char * message,int semid);
void * f_thread_traffic(int * args);
void raw(const char * event,int * sock,int semid,const char * ip_s,int port_s,pthread_mutex_t * socketAccess);
void * f_thread_raw(int * args);
void help();
void * f_thread_checksum(tchecksum* args);
void checksum(const char * event,int * sock, int semid);
#endif /*KEY_HANDLER_H_*/
